package demo.android.com.mvpdemo.mvp3.base;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import demo.android.com.mvpdemo.mvp3.proxy.FragmentMvpProxy;
import demo.android.com.mvpdemo.mvp3.proxy.FragmentMvpProxyImpl;

/**
 * Created by Vya on 2018/1/10 0010.
 */

public abstract class BaseMvpFragment extends Fragment implements BaseView {
    private FragmentMvpProxy mMvpProxy;
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mMvpProxy = createMvpProxy();
        mMvpProxy.bindAndCreatePresenter();
    }
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(getLayoutId(),null,false);
    }
    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);


        initView();
        initData();
    }
    private FragmentMvpProxy createMvpProxy() {
        if(mMvpProxy == null){
            mMvpProxy = new FragmentMvpProxyImpl(this);
        }
        return mMvpProxy;
    }


    protected abstract void initData();
    protected abstract void initView();


    protected abstract int getLayoutId();
}
